package main

import (
	"github.com/julienschmidt/httprouter"
	"net/http"
	"video/api/author"
	"video/api/config"
	"video/api/router"
)

type middleWareHandler struct {
	r *httprouter.Router
}

func NewMiddleWareHandler(r *httprouter.Router) http.Handler {
	m := middleWareHandler{}
	m.r = r
	return &m
}
func (m *middleWareHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {

	if key := author.ValidateUserSession(w,req); key {
		return
	}

	if auth := author.ValidateUser(w, req); !auth {
		return
	}
	m.r.ServeHTTP(w, req)
}

func main() {
	route := router.SetUrl()
	ru := NewMiddleWareHandler(route)
	http.ListenAndServe(config.PORT_URL, ru)
}
